#include <cstdio>
#include <cstring>

#define MAXN 505
#define INF 0x3F3F3F3F
#define MIN(a,b) (a>b?b:a)

int G1[MAXN][MAXN];
int G2[MAXN][MAXN];
int N, M, W;

void floyd(int G[MAXN][MAXN]) {
	for (int k=1; k<=N; k++) {
		for (int i=1; i<=N; i++) {
			for (int j=1; j<=N; j++) {
				G[i][j] = MIN(G[i][j], G[i][k]+G[k][j]);
			}
		}
	}
}

int main() {
	int kase;
	scanf("%d", &kase);
	while (kase--) {
		scanf("%d%d%d", &N, &M, &W);
		memset(G1, 0x3F, sizeof(G1));
		memset(G2, 0x3F, sizeof(G2));
		for (int i=1; i<=M; i++) {
			int S, E, T;
			scanf("%d%d%d", &S, &E, &T);
			G1[S][E] = T;
			G1[E][S] = T;
		}
		for (int i=1; i<=W; i++) {
			int S, E, T;
			scanf("%d%d%d", &S, &E, &T);
			G2[S][E] = -T;
		}
		floyd(G1);
		floyd(G2);
		bool flag = false;
		for (int i=1; i<=N; i++) {
			for (int j=1; j<=N; j++) {
				if (G2[i][j]<INF && G1[i][j]<INF && -G2[i][j]-G1[i][j]>0) {
					//printf("%d-%d  %d\n", i, j, -G2[i][j]-G1[i][j]);
					flag = true;
				}
			}
		}
		if (flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
